package com.kcht.sylyg08.service;

import com.kcht.adp.common.log.Logger;
import com.kcht.adp.pagination.Page;
import com.kcht.sylyg08.dao.IInterveneRecordDao;
import com.kcth.sylyg08.entity.InterveneRecord;

import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.transaction.Transactional;
import java.util.List;
import java.util.Objects;

@RequestScoped
@Transactional()
public class InterveneRecordService {
    @Inject
    private Logger logger;
    @EJB
    private IInterveneRecordDao dao;

    public Page<InterveneRecord, InterveneRecord> list(Page<InterveneRecord, InterveneRecord> page) {
        return dao.getPageListByJPQL("InterveneRecord.queryRecordList", page);
    }
    public void save(InterveneRecord record){
        if(record.getId()==null){
            dao.save(record);
        }else{
            dao.merge(record);
        }
    }

    public void delete(List<Integer> ids) {
        ids.forEach(id->{
            InterveneRecord record = dao.get(id.longValue());
            if(Objects.nonNull(record)){
                dao.delete(id.longValue());
            }
        });
    }

}
